<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Http\Exceptions\HttpResponseException;
use Symfony\Component\HttpFoundation\Response;

class BaseRequest extends FormRequest
{
    /**
     * Handle a failed validation attempt.
     *
     * @param  \Illuminate\Contracts\Validation\Validator  $validator
     * @return void
     *
     * @throws
     */
    protected function failedValidation(\Illuminate\Contracts\Validation\Validator $validator)
    {
        $error      = $validator->errors()->all();
        $error_data = [
            'message' => $error[0],
            'code'    => Response::HTTP_BAD_REQUEST,
            'status'  => 'error'
        ];
        throw new HttpResponseException(response()->json($error_data, Response::HTTP_BAD_REQUEST));
    }
}
